package pair.parking.action;

import pair.parking.common.CommonData;
import pair.parking.bean.Car;

/**
 * Create by Vic Xu on 8/23/2018
 *
 * @author Vic Xu
 * 旧代码（保留不删）
 */
public class CarEvent {

    public String park(Car car) {
        if (isFull()) {
            CommonData.carMap.put(car.getCarTicket().getCode(), car);
            return CommonData.SUCCESS_MSG;
        }
        return CommonData.FAILED_MSG;
    }

    public Car pickUp(String code) {
        if (CommonData.carMap.containsKey(code)) {
            Car car = CommonData.carMap.get(code);
            CommonData.carMap.remove(code);
            return car;
        }
        return null;
    }

    private boolean isFull() {
        return CommonData.carMap.size() < CommonData.MAX_SPACE;
    }
}
